package com.quasar.hpatient.presenter;

import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.model.medicalmodel.PatientInfoData;
import com.quasar.hpatient.model.requestmodel.RequestModel;
import com.quasar.hpatient.onInterface.AnotherResultListener;
import com.quasar.hpatient.onInterface.LoginResultListener;
import com.quasar.hpatient.view.LoginActivity;

/**
 * author : 许建宏
 * Date: 2017/10/20 0020
 * View:
 */

public class LoginPresenter {

    private RequestModel requestModel;
    private LoginResultListener<PatientInfoData> loginActivity;

    public LoginPresenter(LoginResultListener<PatientInfoData> loginActivity){
        this.requestModel=new RequestModel();
        this.loginActivity=loginActivity;
    }

    public void LoginPresenterOperation(final String name, final String pwd){

        requestModel.postLogin(name, pwd, new AnotherResultListener<PatientInfoData>() {
            @Override
            public void onSuccess(PatientInfoData data) {
                loginActivity.onLoginSuccess(data);
            }

            @Override
            public void onError(String msg) {
                loginActivity.onLoginError(msg);
            }

            @Override
            public void onRefreshUI() {
                //保存密码
                MainAppliaction.getInstance().setPwd(pwd);
                //保存账号
                MainAppliaction.getInstance().setUserName(name);
                loginActivity.onLoginRefreshUI();
            }
        });
    }

}
